#include <functional>
#include <iostream>
#include <ostream>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;
class Cow{
	private:
		char name[20];
		char *hobby;
		double weight;
	public:
		Cow();
		Cow(const char *nm,const char *ho,double wt);
		Cow(const Cow &c);
		~Cow();
		Cow &operator=(const Cow &c);
		void ShowCow()const;
		friend ostream & operator<<(ostream &out,const Cow &c);
};
Cow::Cow()
{
	this->name[0]=0;
	this->hobby=nullptr;
	this->weight=0;
}
Cow::Cow(const char *nm,const char *ho,double wt)
{
	strcpy(this->name,nm);
	this->hobby=new char[strlen(ho)+1];
	strcpy(this->hobby,ho);
	this->weight=wt;
}
Cow::Cow(const Cow &c)
{
	strcpy(this->name,c.name);
	this->hobby=new char[strlen(c.hobby)+1];
	strcpy(this->hobby,c.hobby);
	this->weight=c.weight;
}
Cow::~Cow()
{
	if(this->hobby!=nullptr){
		delete [] this->hobby;
		this->hobby=nullptr;
	}
}
Cow& Cow::operator=(const Cow &c)
{
	if(this==&c){
		return *this;	
	}else{
		strcpy(this->name,c.name);
		this->weight=c.weight;
		this->hobby=new char[strlen(c.hobby)+1];
		strcpy(this->hobby,c.hobby);
		return *this;
	}
}
void Cow::ShowCow()const
{
	cout<<this->name<<' '
		<<this->hobby<<' '
		<<this->weight<<endl;
}
int main()
{
	Cow C1("NAME","Hobby",100);
	cout<<C1;
	return 0;
}
ostream & operator<<(ostream &out,const Cow &c)
{
	cout<<c.name<<' '
		<<c.hobby<<' '
		<<c.weight<<endl;
	return out;
}
